package com.lianjinsu.shop.controller.advice;

import com.lianjinsu.shop.controller.vo.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalRestControllerAdvice {

    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    Response<Object> fail(Exception exception) {
        log.error(exception.getLocalizedMessage(), exception);
        return Response.fail(exception.getLocalizedMessage());
    }
}
